local skel = fk.CreateSkill {
  name = "rmt__kuqiu",
  attached_skill_name = "rmt__kuqiu_other&",
}

Fk:loadTranslationTable{
  ["rmt__kuqiu"] = "枯秋",
  [":rmt__kuqiu"] = "其他角色的出牌阶段限一次，其可以交给你一张牌，然后你视为对包括你的至多X名角色使用一张【五谷丰登】。（X为你已损失体力，至少为1）",

  ["#rmt__kuqiu-active"] = "你可以交给有“枯秋”的角色一张牌，令其使用【五谷丰登】",
  ["rmt__kuqiu_other&"] = "枯秋",
  [":rmt__kuqiu_other&"] = "出牌阶段限一次，你可以交给有“枯秋”的角色一张牌，令其选择对包括其的至多X名角色使用一张【五谷丰登】（X为其已损失体力，至少为1）",
  ["#rmt__kuqiu-choose"] = "枯秋：选择你使用【五谷丰登】的其他目标",

  ["$rmt__kuqiu1"] = "昔年作词颂春华，今看秋落，翻飞作萧瑟。",
  ["$rmt__kuqiu2"] = "往日兴赋宴众宾，此间国破，屈身居檐下。",
}

skel:addEffect(fk.GameStart, {
  anim_type = "drawcard",
  can_trigger = Util.FalseFunc,
})

local skel2 = fk.CreateSkill {
  name = "rmt__kuqiu_other&",
}

skel2:addEffect("active", {
  anim_type = "support",
  prompt = "#rmt__kuqiu-active",
  mute = true,
  times = function (self, player)
    local targetRecorded = player:getTableMark("rmt__kuqiu_sources-phase")
    return #table.filter(Fk:currentRoom().alive_players, function(p)
      return p ~= player and p:hasSkill(skel.name) and not table.contains(targetRecorded, p.id)
    end)
  end,
  can_use = function(self, player)
    local targetRecorded = player:getTableMark("rmt__kuqiu_sources-phase") -- 每个技能拥有者单独计算
    return table.find(Fk:currentRoom().alive_players, function(p)
      return p ~= player and p:hasSkill(skel.name) and not table.contains(targetRecorded, p.id)
    end)
  end,
  card_num = 1,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  target_num = 1,
  target_filter = function (self, player, to_select, selected)
    if #selected == 0 and to_select ~= player and to_select:hasSkill(skel.name) then
      local targetRecorded = player:getTableMark("rmt__kuqiu_sources-phase")
      return not table.contains(targetRecorded, to_select)
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:notifySkillInvoked(target, skel.name)
    target:broadcastSkillInvoke(skel.name)
    room:addTableMark(player, "rmt__kuqiu_sources-phase", target.id)
    room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, self.name, nil, true)
    if target.dead then return end
    local card = Fk:cloneCard("amazing_grace")
    card.skillName = "rmt__kuqiu"
    if target:prohibitUse(card) or target:isProhibited(target, card) then return end
    local x = math.max(1, target:getLostHp()) - 1
    local targets = {target}
    local avail = table.filter(room:getOtherPlayers(target), function (p) return not target:isProhibited(p, card) end)
    if #avail > 0 and x > 0 then
      local tos = room:askToChoosePlayers(target,{ targets = avail, min_num = 1, max_num = x,
      prompt = "#rmt__kuqiu-choose", skill_name = self.name})
      if #tos > 0 then
        table.insertTable(targets, tos)
      end
    end
    room:useCard{from = target, tos = targets, card = card}
  end,
})

return {skel, skel2}
